package javaTest01;

import java.util.Scanner;

public class DaysOfYearJudgment {
    public static void main(String[] args) {
        Scanner input=new Scanner(System.in);
        System.out.println("输入年");
        int year=input.nextInt();
        System.out.println("输入月");
        int month=input.nextInt();
        System.out.println("输入日");
        int day=input.nextInt();
        int res=getDaysOfYear(year,month,day);
        if (res>0)
            System.out.println("为第"+year+"年中的第"+res+"天");
        else
            System.out.println("输入非法");
    }

    private static int getDaysOfYear(int year, int month, int day) {
        if (year*month*day<=0)
            return -1;
        int[] monthArr=getMonthArr(year);
        int days=0;
        for (int i=0;i<month-1;i++){
            days+=monthArr[i];
        }
        return days+day;
    }
    public static boolean isLeapYear(int year){
        return year % 100 == 0 || (year % 4 == 0 && year % 100 != 0);
    }
    public static int[] getMonthArr(int year){
        int[] monthsArr={31,29,31,30,31,30,31,31,30,31,30,31};
        if (isLeapYear(year))
            monthsArr[1]=28;
        return monthsArr;
    }
}
